package com.sztx.pay.center.core.service.bean;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 
 * @ClassName: BillnoModel
 * @Description: 
 * @author jsu
 * @date 2015年1月26日 上午10:46:49
 *
 */
@SuppressWarnings("serial")
public class BillnoModel implements Serializable {
	
	private long startSeq;
	
	private long currentSeq;
	
	private long maxSeq;
	
	private int step;
	
	private String date = null;
	
	private AtomicLong seq = new AtomicLong(0);
	
	private long[] batchSeqs = null;
	
	private int type;
	
	private String orderStyle;
	
	private String prefix;
	
	
	
	/**
	 * 
	 * @Title: isneed
	 * @Description: 判断是否需要从DB获取
	 * @param @return    设定文件
	 * @return boolean    返回类型
	 * @throws
	 */
	public boolean isneed() {
		if (seq.get() >= maxSeq) {
			return true;
		}
		return false;
	}
	
	/**
	 * 
	 * @Title: getCurrentValue
	 * @Description: 一次获取一个单号
	 * @param @return    设定文件
	 * @return long    返回类型
	 * @throws
	 */
	public long getCurrentValue() {
		return seq.getAndIncrement();
	}
	
	/**
	 * 
	 * @Title: getCurrentValue
	 * @Description: 一次获取一个单号
	 * @param @return    设定文件
	 * @return long    返回类型
	 * @throws
	 */
	public long[] getBatchValue(int num) {
		long[] results = new long[num];
		for(int i=0; i<num; i++) {
			results[i] = seq.getAndIncrement();
		}
		return results;
	}
	
	/**
	 * 
	 * @Title: getCacheNum
	 * @Description: 获取当前缓存可用个数
	 * @param @return    设定文件
	 * @return long    返回类型
	 * @throws
	 */
	public long getCacheNum() {
		return this.maxSeq - seq.get();
	}

	/**
	 * @return the startSeq
	 */
	public long getStartSeq() {
		return startSeq;
	}

	/**
	 * @param startSeq the startSeq to set
	 */
	public void setStartSeq(long startSeq) {
		this.startSeq = startSeq;
	}

	/**
	 * @return the currentSeq
	 */
	public long getCurrentSeq() {
		return currentSeq;
	}

	/**
	 * @param currentSeq the currentSeq to set
	 */
	public void setCurrentSeq(long currentSeq) {
		this.currentSeq = currentSeq;
		seq.set(currentSeq);
	}

	/**
	 * @return the maxSeq
	 */
	public long getMaxSeq() {
		return maxSeq;
	}

	/**
	 * @param maxSeq the maxSeq to set
	 */
	public void setMaxSeq(long maxSeq) {
		this.maxSeq = maxSeq;
	}

	/**
	 * @return the step
	 */
	public int getStep() {
		return step;
	}

	/**
	 * @param step the step to set
	 */
	public void setStep(int step) {
		this.step = step;
	}

	/**
	 * @return the date
	 */
	public String getDate() {
		return date;
	}

	/**
	 * @param date the date to set
	 */
	public void setDate(String date) {
		this.date = date;
	}

	/**
	 * @return the batchSeqs
	 */
	public long[] getBatchSeqs() {
		return batchSeqs;
	}

	/**
	 * @param batchSeqs the batchSeqs to set
	 */
	public void setBatchSeqs(long[] batchSeqs) {
		this.batchSeqs = batchSeqs;
	}

	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}

	public String getOrderStyle() {
		return orderStyle;
	}

	public void setOrderStyle(String orderStyle) {
		this.orderStyle = orderStyle;
	}

	public String getPrefix() {
		return prefix;
	}

	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}
	
	
	
}
